package com.example.cmscrud.demo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.cmscrud.demo.entity.Users;
import com.example.cmscrud.demo.mapper.UsersMapper;
import com.example.cmscrud.demo.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;
    @Override
    public List<Users> getAllUser(Integer page, Integer limit) {
        IPage<Users> usersIPage=new Page<>(page,limit);
        IPage<Users> result=usersMapper.selectPage(usersIPage,null);
        List<Users> users=result.getRecords();
        return users;
    }

    @Override
    public int insertUser(Users users) {
//        System.out.println(users);
        return usersMapper.insert(users);
    }

    @Override
    public int deleteUser(int id) {
        return usersMapper.deleteById(id);
    }

    @Override
    public int updateUser(Users users) {
        return usersMapper.updateById(users);
    }
}
